﻿using System;
using System.Data;
using System.Web;
using System.Text;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.BIZ;
using System.Reflection;
using System.Data.SqlClient;
using log4net;
using Microsoft.ApplicationBlocks.Data;

namespace AnyOffice.general.system.res_manage
{
    public partial class set : ModulePage
    {

        private static ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
       
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                DataTable table = new UserPrivDao().SelectAll(base.Conn);
                this.ddlPrivId.DataSource = table;
                this.ddlPrivId.DataValueField = "PrivId";
                this.ddlPrivId.DataTextField = "PrivName";
                this.ddlPrivId.DataBind();
            }
            if (this.Page.IsPostBack)
            {
                this.pnlMain.Visible = false;
                try
                {
                    string commandText = string.Empty;
                    SqlParameter[] commandParameters = new SqlParameter[2];
                    commandParameters[0] = new SqlParameter("@PrivId", SqlDbType.Int);
                    commandParameters[0].Value = Convert.ToInt32(this.ddlPrivId.SelectedValue);
                    commandParameters[1] = new SqlParameter("@Capacity", SqlDbType.Int);
                    commandParameters[1].Value = Convert.ToInt32(this.txtCapacity.Text);
                    if (this.ddlModule.SelectedValue == "EmailCapacity")
                    {
                        commandText = "UPDATE [dbo].[Users] SET [EmailCapacity] = @Capacity WHERE [PrivId] = @PrivId";
                    }
                    else
                    {
                        commandText = "UPDATE [dbo].[Users] SET [FolderCapacity] = @Capacity WHERE [PrivId] = @PrivId";
                    }
                    SqlHelper.ExecuteNonQuery(base.Conn, CommandType.Text, commandText, commandParameters);
                    this.litMessage.Text = base.ShowPrompt("设置已保存", "set.aspx");
                }
                catch (Exception exception)
                {
                    this.litMessage.Text = base.ShowPrompt("设置失败", "set.aspx");
                    if (log.IsErrorEnabled)
                    {
                        log.Error("", exception);
                    }
                }
            }
        } 

    }
}
